<template lang="pug">
.scenepay-model
  el-dialog(
    width="30%",
    title="场景付费",
    :visible.sync="isShow",
    :before-close="handleClose")

    .scenepay-model-content
      .item.payment.clearfix
        .label 付款方式 :
        el-radio-group.fr(v-model="payment")
          el-radio(size="small", label="3", border) 账户余额
          el-radio(size="small", label="1", border) 支付宝
          el-radio(size="small", label="2", border) 微信
      .item.buy-money.mt20
        span.label {{value ? '全部金额' : '单个金额'}} :
        strong.red.fr {{ value ? this.getAllPayMoney : this.getOnePayMoney }} 元
      .item.buy-method.mt20
        .label 购买方式 :
        el-switch.fr(
          v-model="value",
          active-color="#ff4949",
          inactive-color="#13ce66",
          active-text="全部付费",
          inactive-text="单个付费",
          @change="changePayment")

    span.dialog-footer(slot="footer")
      el-button(size="small", @click="hide") 取 消
      el-button(size="small", type="primary", @click="handleSure") 确 定

</template>

<script>
import { mapGetters } from 'vuex'
import autoSwitchSceneMixin  from '@/mixins/switch-scene'

export default {
  mixins: [autoSwitchSceneMixin],
  data() {
		return {
      isShow: false,
      value: false,
      ordertype: 6,
      payment: '3',
      sceneId: null,
		}
  },
  mounted() {
    this.$vgo.on('scenepay:show', scene => {
      // console.log('5---------------11')
      // console.log(scene.scene_id)
      this.sceneId = scene.scene_id
      this.show()
      // 清除场景自动切换
      this.handleClearAutoSwitchScene()
    })

    this.$vgo.on('scenepay:success', sceneId => {
      this.$vgo.tip('支付成功', 'success')

      // 更新场景数据
      this.$vgo.emit('update:scene', sceneId)



      this.hide()
    })

    this.$vgo.on('scenepay:failed', () => {
      this.$vgo.tip('支付失败', 'faile')
    })
  },
   computed: {
    ...mapGetters(['panoId', 'scenePayData']),
    getOnePayMoney() {
      if(this.scenePayData) {
        return this.scenePayData.onepaycount
      }
    },
    getAllPayMoney() {
      if(this.scenePayData) {
        return this.scenePayData.allpaycount
      }
    },
    getCurrentMoney() {
      if(this.scenePayData) {
        return this.ordertype == '6' ? this.scenePayData.onepaycount : this.scenePayData.allpaycount
      }
    }
  },
  methods: {
    changePayment(val) {
      this.ordertype = val ? 7 : 6
    },
    handleSure() {
      let options = {
        panoId: this.panoId,
        ordertype: this.ordertype, // 单个6 全部7
        paytype: Number(this.payment),
        productid: this.ordertype == 7 ? this.panoId : this.sceneId, // 单场景sceneid 全部panoid
        totalfee: this.getCurrentMoney,
        return_url: $globalconfig.URLS.PANO_VIEW_PREFIX + this.panoId
      }
      // 微信 2 支付宝 1 余额 3
      options.iswx = 'false'
      this.$store.dispatch('scenePay', options)
    },
    handleClose(done) {
      this.hide()
      done()
    },
		show() {
			this.isShow = true
    },
    hide() {
      this.isShow = false
      // 付费成功后，重新开始场景切换
      this.handleRestartAutoSwitchScene()
    }
  }
}
</script>

<style lang="stylus">

.scenepay-model-content
  .item
    .label
      display: inline-block
      width: 80px

</style>


